let gulp = require('gulp');
let del = require('del');
let build = require('./build');
let func = require('./helpers');

/**
 * 清空
 */

/**
 * 获取要删除目录中内容
 *
 * @param outPaths {array} 目录
 * @returns {[]}
 */
let getPaths = function(outPaths) {
	if (typeof outPaths === 'undefined'){
		outPaths = [];
	}
	let paths = [];
	let outputs = build.config.dist;
	outputs.forEach(function(output) {
		// has demo placeholder
		if (output.indexOf('**') !== -1) {
			func.getDemos().forEach(function(demo) {
				paths.push(output.replace('**', demo));
			});
		} else {
			if (outPaths.length === 0) {
				paths.push(output);
			}
			outPaths.forEach(function(path) {
				paths.push(output + '/' + path);
			});
		}
	});

	let realPaths = [];
	paths.forEach(function(path) {
		realPaths.push(path + '/*');
		realPaths.push('!' + path + '/lib');
	});

	return realPaths;
};
// 清除task
gulp.task('clean', function() {
	return del(getPaths(), {force: true});
});